<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<script type="text/javascript">
			var getUrlData = {
				callback: null,
				_t: 0,
				init(fn) {
					this.callback = fn;
					this.bind();
					this.change.call(this);
				},
				bind() {
					let that = this;
					if (("onhashchange" in window) && ((typeof document.documentMode === "undefined") || document.documentMode == 8)) {
						window.onhashchange = () => {
							that.change.call(that);
						};
					} else {
						clearInterval(this._t);
						this._t = setInterval(() => {
							that.change.call(that);
						}, 150);
					}
				},
				change() {
					let that = this,
						_hash = window.location.hash,
						_data = null;
					try {
						_data = JSON.parse(decodeURIComponent(_hash.split('#')[1]));
					} catch (e) {
						_data = decodeURIComponent(_hash.split('#')[1]);
					}
					if (that.callback) that.callback({
						type: that.getQuery('type'),
						data: _data
					});
				},
				getQuery(name) {
					let reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
					let r = decodeURIComponent(window.location.search).substr(1).match(reg);
					if (r != null) {
						// 对参数值进行解码
						return decodeURIComponent(r[2]);
					}
					return null;
				}
			}
			getUrlData.init(function(res){
				console.log(res)
			})
		</script>
	</body>
</html>
